/*封装与月份信息的有关的ajax查询，更改等*/

require.config({
    paths: {
        "common": "../common/common"
    }
});
define(['common'], function(common) {
    var baseUrl = common.defaultStr();
    var month_url = {
        'modifyMoney': baseUrl + '/mgr/je/add.do',
        'getMoney': baseUrl + '/mgr/je/get.do',
        'addMonth': baseUrl + '/usr/date/add.do',
        'delMonth': baseUrl + '/usr/date/remove.do',
        'getMonths': baseUrl + '/usr/date/getAll.do',
        'getJe': baseUrl + '/mgr/je/get.do'
    };
    /*查询月份 GET形式*/
    function getMonth() {
        return $.ajax({
            type: "GET",
            url: month_url.getMonths,
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }
    /*删除月份 POST-URL形式*/
    function delMonth(id) {
        var newUrl = month_url.delMonth + '?' + 'id=' + id;
        return $.ajax({
            type: "POST",
            url: newUrl,
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }
    /*添加月份POST*/
    function addMonth(query) {
        return $.ajax({
            type: "POST",
            url: month_url.addMonth,
            data: JSON.stringify(query),
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
        }).done(
            handleSessionTimeOut
        );
    }

    function handleSessionTimeOut(data) {
        if (data && data.retcode === '202') {
            location.reload();
        }
    }
    return {
        getMonth,
        delMonth,
        addMonth,
    }
})
